import re

def is_prime(num):
    if num <= 1:
        return False
    if num <= 3:
        return True
    if num % 2 == 0 or num % 3 == 0:
        return False
    i = 5
    while i  *  i <= num:
        if num % i == 0 or num % (i + 2) == 0:
            return False
        i += 6
    return True

def find_closest_prime(number):
    while True:
        number += 1
        if is_prime(number):
            return number

def process_input():
    words = input().strip().split()
    if len(words) != 3:
        print("Wrong input")
        return
    
    num1 = int(re.sub(r'\D', '', words[0]))
    num2 = int(re.sub(r'\D', '', words[1]))
    num3 = int(re.sub(r'\D', '', words[2]))
    
    if num1 > 9 or num2 > 9 or num3 > 9:
        print("Wrong input")
        return
    
    number = num1  *  100 + num2  *  10 + num3
    
    result = find_closest_prime(number)
    print(result)

process_input()
